import os
from typing import Dict, Any
from datetime import timedelta

class Config:
    # 应用配置
    SECRET_KEY = os.getenv('SECRET_KEY', 'your-secret-key')
    DEBUG = os.getenv('FLASK_DEBUG', 'False').lower() == 'true'
    
    # 数据库配置
    MYSQL_HOST = os.getenv('MYSQL_HOST', 'localhost')
    MYSQL_PORT = int(os.getenv('MYSQL_PORT', '3306'))
    MYSQL_USER = os.getenv('MYSQL_USER', 'root')
    MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD', '123456')
    MYSQL_DB = os.getenv('MYSQL_DB', 'fund_db')
    
    # 企业微信配置
    WECHAT_CORP_ID = os.getenv('WECHAT_CORP_ID', 'your_corp_id')
    WECHAT_CORP_SECRET = os.getenv('WECHAT_CORP_SECRET', 'your_corp_secret')
    WECHAT_AGENT_ID = os.getenv('WECHAT_AGENT_ID', 'your_agent_id')
    
    # JWT配置
    JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'your-jwt-secret-key')
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=24)
    JWT_TOKEN_LOCATION = ['headers']
    JWT_HEADER_NAME = 'Authorization'
    JWT_HEADER_TYPE = 'Bearer'
    
    # 基金API配置
    FUND_API_URL = 'http://fund.eastmoney.com/pingzhongdata/{}.js'
    
    # 定时任务配置
    SCHEDULER_API_ENABLED = True
    SCHEDULER_TIMEZONE = 'Asia/Shanghai'
    
    # 日志配置
    LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
    LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    
    @classmethod
    def get_db_config(cls) -> Dict[str, Any]:
        """获取数据库配置"""
        return {
            'host': cls.MYSQL_HOST,
            'port': cls.MYSQL_PORT,
            'user': cls.MYSQL_USER,
            'password': cls.MYSQL_PASSWORD,
            'db': cls.MYSQL_DB,
            'charset': 'utf8mb4'
        } 